package mypack;

//DES程序中的一些数值转换
import java.util.*;

public class numberChange {

    //将十进制转为指定位数的二进制字符串
    public static String toBinary(int num, int dig) {
        int tmp = 1 << dig | num;
        String se = Integer.toBinaryString(tmp);
        return se.substring(1); 
    }

    //字节数组转二进制字符串
    public static StringBuilder byteToBin(byte[] b) {
        StringBuilder result = new StringBuilder();
        for(int i = 0; i < b.length; i++)
            result.append(toBin(b[i]));//toBin()将单个byte字节转为二进制字符串
        return result;
    }

    //字节转二进制字符串
    public static String toBin(byte b) {
        return Integer.toBinaryString((b & 0xFF) + 0x100).substring(1);
    }

    //将64位二进制字符串转为字节数组byte[8]
    public static byte[] binToByte(String bin) {
        byte[] bb = new byte[8];
        for(int i = 0; i < 8; i++) {
            String tmp = bin.substring( i*8, (i+1)*8 );
            //bb[i] = Byte.parseByte(tmp, 2);
            bb[i] = Integer.valueOf(tmp, 2).byteValue();
        }
        return bb;
    }

    public static void main(String[] args) {
        Byte bb = new Byte(args[0]);
        System.out.println(toBin(bb.byteValue()));
    }
}